define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

	var Controller = {
		index: function() {
			// 初始化表格参数配置
			Table.api.init({
				extend: {
					index_url: 'qikan/index' + location.search,
					add_url: 'qikan/add',
					edit_url: 'qikan/edit',
					del_url: 'qikan/del',
					multi_url: 'qikan/multi',
					import_url: 'qikan/import',
					table: 'qikan',
				}
			});

			var table = $("#table");

			// 初始化表格
			table.bootstrapTable({
				url: $.fn.bootstrapTable.defaults.extend.index_url,
				pk: 'id',
				sortName: 'weigh',
				fixedColumns: true,
				fixedRightNumber: 1,
				columns: [
					[{
							checkbox: true
						},
						{
							field: 'id',
							title: __('Id')
						},
						{
							field: 'image',
							title: __('Image'),
							operate: false,
							events: Table.api.events.image,
							formatter: Table.api.formatter.image
						},
						{
							field: 'name',
							title: __('Name'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'jidu_price',
							title: __('Jidu_price'),
							operate: 'BETWEEN'
						},
						{
							field: 'bannian_price',
							title: __('Bannian_price'),
							operate: 'BETWEEN'
						},
						{
							field: 'yinian_price',
							title: __('Yinian_price'),
							operate: 'BETWEEN'
						},
						{
							field: 'zhuguandanwei',
							title: __('Zhuguandanwei'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'zhubandanwei',
							title: __('Zhubandanwei'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'xiebandanwei',
							title: __('Xiebandanwei'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'faxingzhouqi',
							title: __('Faxingzhouqi'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'guoneikanhao',
							title: __('Guoneikanhao'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'guojikanhao',
							title: __('Guojikanhao'),
							operate: 'LIKE',
							table: table,
							class: 'autocontent',
							formatter: Table.api.formatter.content
						},
						{
							field: 'content_file',
							title: __('Content_file'),
							operate: false,
							formatter: Table.api.formatter.file
						},
						{
							field: 'weigh',
							title: __('Weigh'),
							operate: false
						},
						{field: 'show_switch', title: __('Show_switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
						{
							field: 'updatetime',
							title: __('Updatetime'),
							operate: 'RANGE',
							addclass: 'datetimerange',
							autocomplete: false,
							formatter: Table.api.formatter.datetime
						},
						{
							field: 'operate',
							title: __('Operate'),
							table: table,
							events: Table.api.events.operate,
							buttons: [
								 {
									name: 'detail',
									text: __('期刊期数'),
									title: __('期刊期数'),
									classname: 'btn btn-xs btn-primary btn-dialog',
									icon: 'fa fa-list',
									url: 'qikanqishu/index',
									callback: function (data) {
										Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
									},
									visible: function (row) {
										//返回true时按钮显示,返回false隐藏
										return true;
									}
								},
							],
							formatter: Table.api.formatter.operate
						}
					]
				]
			});

			// 为表格绑定事件
			Table.api.bindevent(table);
		},
		add: function() {
			Controller.api.bindevent();
		},
		edit: function() {
			Controller.api.bindevent();
		},
		api: {
			bindevent: function() {
				Form.api.bindevent($("form[role=form]"));
			}
		}
	};
	return Controller;
});